package com.tencent.wxcloudrun.frontcontroller;

import com.alibaba.fastjson.JSONObject;
import com.tencent.wxcloudrun.dto.*;
import com.tencent.wxcloudrun.mapper.BannerMapper;
import com.tencent.wxcloudrun.mapper.ShopconfigMapper;
import com.tencent.wxcloudrun.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2023/3/4 19:22
 * @description: TODO
 */
@RestController
@Api(tags = "门店信息")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @Autowired
    private ShopconfigMapper shopConfigMapper;

    @Autowired
    private BannerMapper bannerMapper;

    /**
     * 获取门店详情
     */
    @Operation(summary = "微信小程序获取门店详情免code")
    @PostMapping(value = "/wxcloud/shopSubdetail")
    ShopSubdetailResponse shopSubdetail(HttpServletRequest request, @RequestBody ShopSubdetaiRequest json) {
        String shopIdZt = json.getShopIdZt();
        Shop shop =   shopService.shopSubdetail(shopIdZt);
        ShopSubdetailResponse response = new ShopSubdetailResponse();
        if (shop != null) {
            response.setCode(0);
            response.setMsg("获取成功");
            ShopSubdetail shopSubdetail = new ShopSubdetail();
            shopSubdetail.setInfo(shop);
            shopSubdetail.setExtJson(null);
            response.setData(shopSubdetail);
            return response;
        } else {
            response.setCode(400);
            response.setMsg("获取失败");
            return response;
        }
    }

    @Operation(summary = "获取门店配置开发调试中")
    @PostMapping(value = "/wxcloud/queryConfigBatch")
    JSONObject queryConfigBatch(HttpServletRequest request) {
    List<Shopconfig> shopconfig =  shopConfigMapper.selectByPrimaryKey();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("data",shopconfig);
        jsonObject.put("msg","获取成功");
        return jsonObject;
    }

    /**
     * 获取门店列表
     */
    @Operation(summary = "获取门店列表")
    @PostMapping("/wxcloud/fetchShops")
    FetchShopsResponse fetchShops(HttpServletRequest request, @RequestBody FetchShopsRequest json) {
        String curlatitude = json.getCurlatitude();
        System.out.println(curlatitude);
        List<Shop>  shops = shopService.shopSubdetails();
        FetchShopsResponse response = new FetchShopsResponse();
        if (shops != null) {
            response.setCode(0);
            response.setMsg("获取成功");
            response.setData(shops);
            return response;
        } else {
            response.setCode(400);
            response.setMsg("获取失败");
            return response;
        }
    }

    /**
     * Banner列表
     */
    @Operation(summary = "Banner列表")
    @PostMapping("/wxcloud/banners")
    BannersResponse banners(HttpServletRequest request, @RequestBody BannersRequest json) {
        List<Banner> banners = bannerMapper.selectBanners();
        BannersResponse response = new BannersResponse();
        if (banners != null) {
            response.setCode(0);
            response.setMsg("获取成功");
            response.setData(banners);
            return response;
        } else {
            response.setCode(400);
            response.setMsg("获取失败");
            return response;
        }

    }


    /**
     * 获取视频点播详情
     */
    @Operation(summary = "获取视频点播详情")
    @PostMapping("/wxcloud/videoDetail")
    VideoDetailResponse videoDetail(HttpServletRequest request, @RequestBody VideoDetailRequest json) {
        return null;
    }

}
